home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ddj0290.arc / DUNTEMAN.LST < prev    next >
File List  |  1990-01-07  |  4KB  |  112 lines

  1. _STRUCTURED PROGRAMMING COLUMN_
  2. by Jeff Duntemann
  3.  
  4. [LISTING ONE]
  5.  
  6. MODULE JTerm;
  7.  
  8. (* Stony Brook Modula-2 --  Last modified 10/31/89 *)
  9. (* by Jeff Duntemann    --  For DDJ 2/90 *)
  10.  
  11. FROM CommPort IMPORT BaudRate, Parity, InitPort, StartReceiving,
  12.                      StopReceiving, SendChar, GetChar, CommStatus;
  13.  
  14. FROM FileSystem IMPORT Close, File, Length, Lookup, Reset, SetPos, WriteChar;
  15.      
  16. FROM Keyboard IMPORT GetKey, CarriageReturn, LineFeed, AltX, F7, F8;     
  17.  
  18. FROM Screen   IMPORT CreateWindow, CloseWindow, Color, DrawBorder, 
  19.                      MakeColorAttr, Position, SetCursor, Window, 
  20.              WriteString, WriteLn, Xpos, Ypos;
  21.      
  22. FROM Terminal IMPORT Write, CharAvail, Read;
  23.  
  24. CONST
  25.   Blink   = TRUE;
  26.   NoBlink = FALSE;
  27.   AsPopup = TRUE;
  28.   NotAsPopup = FALSE;
  29.   CreateFile = TRUE;
  30.  
  31. VAR
  32.   CaptureOn   : BOOLEAN;
  33.   CaptureFile : File;
  34.   ItsLength   : LONGINT;
  35.   Status      : CommStatus;
  36.   Ch          : CHAR;
  37.   OutString   : ARRAY[0..1] OF CHAR;
  38.   Keystroke   : CARDINAL;
  39.   W           : Window;
  40.   WhiteOnBlue : CHAR;
  41.   
  42. BEGIN
  43.   (* First set up the window to hold the terminal session: *)
  44.   WhiteOnBlue := MakeColorAttr(White,Blue,NoBlink);
  45.   W := CreateWindow(0,0,80,24,WhiteOnBlue,AsPopup);
  46.   DrawBorder(W,MakeColorAttr(White,LightCyan,NoBlink));
  47.   Position(W,1,0);
  48.   WriteString(W,'\\\\JTERM\\\\  by Jeff Duntemann ',
  49.               MakeColorAttr(Black,LightCyan,Blink));
  50.   Position(W,1,1);  
  51.   SetCursor(W);
  52.   
  53.   (* Here we look for the capture file CAPTURE.TXT; open it if it  *)
  54.   (* exists, and create it if it doesn't:  *)
  55.   Lookup(CaptureFile,"CAPTURE.TXT",CreateFile);
  56.   Length(CaptureFile,ItsLength);  (* Find out how long file is...  *)
  57.   SetPos(CaptureFile,ItsLength);  (* ...and position it to EOF.    *)
  58.   CaptureOn := FALSE;             (* Default to NOT capturing text *)
  59.   
  60.   (* Next, set up the interrupt-driven serial port and turn it on: *)
  61.   Status := InitPort(0,Baud1200,7,1,Even);
  62.   Status := StartReceiving(0,256);
  63.   
  64.   (* We check for keystrokes, then check for incoming data: *)
  65.   LOOP  (* EXIT the loop (and the program) on Alt-X *)
  66.     IF CharAvail() THEN
  67.       GetKey(Keystroke);  (* Get a keystroke from the buffer *)
  68.       CASE Keystroke OF
  69.         CarriageReturn:   (* If CR was pressed, send CR *AND* LF: *)
  70.       SendChar(0,CHR(CarriageReturn),FALSE);
  71.       SendChar(0,CHR(LineFeed),FALSE); |
  72.     F7: CaptureOn := TRUE;  |  (* F7/F8 toggle capture *)
  73.     F8: CaptureOn := FALSE; |  (*  on and off *)
  74.     AltX: EXIT;                (* Alt-X quits the program *)
  75.     (* Send any non-command to the serial port: *)
  76.     ELSE SendChar(0,CHR(Keystroke),FALSE);
  77.       END;    
  78.     END;
  79.     (* If a char's waiting in the comm buffer, get it and parse it: *)
  80.     IF GetChar(0,Ch) = Success THEN
  81.       OutString[0] := Ch;
  82.       CASE ORD(Ch) OF
  83.          (* This is how we fake TTY backspace: *)
  84.          8: IF Xpos(W) > 0 THEN
  85.           Position(W,Xpos(W)-1,Ypos(W));
  86.           WriteString(W,' ',WhiteOnBlue);
  87.           Position(W,Xpos(W)-1,Ypos(W));
  88.           SetCursor(W);
  89.         END;          |  
  90.         13: WriteLn(W);
  91.         SetCursor(W); 
  92.         IF CaptureOn THEN
  93.           WriteChar(CaptureFile,Ch)
  94.         END;          |
  95.     10: IF CaptureOn THEN
  96.           WriteChar(CaptureFile,Ch)
  97.         END;               
  98.         ELSE WriteString(W,Ch,WhiteOnBlue);
  99.          SetCursor(W);
  100.          IF CaptureOn THEN
  101.            WriteChar(CaptureFile,Ch);
  102.          END;  
  103.       END;    
  104.     END;      
  105.   END;
  106.   (* Finally, we shut down the interrupt-driven input buffer: *)
  107.   Status := StopReceiving(0);
  108.   Close(CaptureFile);
  109. END JTerm.
  110.   
  111.  
  112.